/**
 * 
 */
package org.swing.utility.input.action;

import javax.swing.event.*;
import javax.swing.text.JTextComponent;
import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * @author Le Quynh Nhu
 * 
 */
public abstract class UIListener implements DocumentListener, ItemListener,
		ListDataListener, ListSelectionListener, TableModelListener,
		TreeModelListener, TreeSelectionListener {

	public abstract void changed();

	/*-------------------------------------------------[ DocumentListener ]---------------------------------------------------*/

	public void insertUpdate(DocumentEvent de) {
		changed();
	}

	public void removeUpdate(DocumentEvent de) {
		changed();
	}

	public void changedUpdate(DocumentEvent de) {
		changed();
	}

	/*-------------------------------------------------[ ItemListener ]---------------------------------------------------*/

	public void itemStateChanged(ItemEvent ie) {
		changed();
	}

	/*-------------------------------------------------[ ListDataListener ]---------------------------------------------------*/
	public void intervalAdded(ListDataEvent lde) {
		changed();
	}

	public void intervalRemoved(ListDataEvent lde) {
		changed();
	}

	public void contentsChanged(ListDataEvent lde) {
		changed();
	}

	/*-------------------------------------------------[ ListSelectionListener ]---------------------------------------------------*/

	public void valueChanged(ListSelectionEvent lse) {
		changed();
	}

	/*-------------------------------------------------[ TableModelListener ]---------------------------------------------------*/

	public void tableChanged(TableModelEvent tme) {
		changed();
	}

	/*-------------------------------------------------[ TreeModelListener ]---------------------------------------------------*/

	public void treeNodesChanged(TreeModelEvent tme) {
		changed();
	}

	public void treeNodesInserted(TreeModelEvent tme) {
		changed();
	}

	public void treeNodesRemoved(TreeModelEvent tme) {
		changed();
	}

	public void treeStructureChanged(TreeModelEvent tme) {
		changed();
	}

	/*-------------------------------------------------[ TreeSelectionListener ]---------------------------------------------------*/

	public void valueChanged(TreeSelectionEvent tse) {
		changed();
	}

	/*-------------------------------------------------[ ListenTo ]---------------------------------------------------*/

	public void listenTo(JTextComponent textComp) {
		textComp.getDocument().addDocumentListener(this);
	}

	public void listenTo(AbstractButton button) {
		button.addItemListener(this);
	}

	public void listenTo(JList list, boolean model, boolean selection) {
		if (model)
			list.getModel().addListDataListener(this);
		if (selection)
			list.addListSelectionListener(this);
	}

	public void listenTo(JTable table, boolean model, boolean selection) {
		if (model)
			table.getModel().addTableModelListener(this);
		if (selection)
			table.getSelectionModel().addListSelectionListener(this);
	}

	public void listenTo(JTree tree, boolean model, boolean selection) {
		if (model)
			tree.getModel().addTreeModelListener(this);
		if (selection)
			tree.addTreeSelectionListener(this);
	}
}
